<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../css/app.css" />
		<link rel="stylesheet" type="text/css" href="css/login.css" />
		<!--<link rel="stylesheet" type="text/css" href="css/register.css" />-->
		<link rel="stylesheet" type="text/css" href="../css/iconfont.css" />
		<link href="../css/mui.picker.min.css" rel="stylesheet" />
		<link href="../css/mui.poppicker.css" rel="stylesheet" />
		<style>
			.logininfo {
				background-color: #FFFFFF;
				border-radius: 5px;
				margin: 20px 20px 0px 20px;
				padding: 20px 20px 20px 20px;
			}
			
			.mui-input-row span {
				display: block;
				width: 15%;
			}
			
			.iconfont {
				font-size: 1.5rem;
				vertical-align: middle;
				color: #444444;
			}
			
			.mui-input-row textarea {
				border: 0;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left backbtn"></a>
			<h1 class="mui-title">收货地址</h1>
			<a class=" mui-pull-right homebtn" href="#" id="userResult"></a>
		</header>
		<div class="mui-content">
			<div class="logininfo">
				<div class="mui-input-row" id='showUserPicker'>
					<label></label>
					<input type="text" id="city" class=" mui-input" placeholder="省市区">
				</div>
				<div class="mui-input-row">
					<textarea class="mui-input" placeholder="详细地址" id="address"></textarea>
				</div>
				<div class="mui-input-row">
					<label></label>
					<input id='truename' type="text" class=" mui-input" placeholder="收货人">
				</div>
				<div class="mui-input-row">
					<label class=" "></label>
					<input id='phone' type="text" class=" mui-input" placeholder="手机号">
				</div>
			</div>
			<div class="btn">
				<button type="button" class="mui-btn mui-btn-yellow mui-btn-block addressSub">保存</button>
			</div>
		</div>
		<script src="../lib/mui.min.js"></script>
		<script src="../lib/mui.picker.min.js"></script>
		<script src="../lib/mui.poppicker.js"></script>
		<script src="../lib/city.data.js"></script>
		<script src="../lib/city.data-3.js"></script>
		<script type="text/javascript" src="../lib/jquery-1.11.0.js"></script>
		<script type="text/javascript" src="../lib/Verification.js" ></script>
		<script type="text/javascript" src="../lib/service.js"></script>

		<script type="text/javascript">
			mui.init()
			mui.plusReady(function() {
				plus.navigator.setStatusBarBackground("#FF7234");
				var str = plus.webview.currentWebview().parms
				console.log(str)
				var parms
				if(str == "" || str == null){
					parms = {id:2} ;
				}else{
					 parms = JSON.parse(str) ;
				}
				
				
				var setcity = new mui.PopPicker({
					layer: 3
				});
				setcity.setData(cityData3);
				$('#showUserPicker').bind('tap', function(event) {
					setcity.show(function(items) {
						console.log(items)
						$('#city').val(items[0].text + "-" + items[1].text + "-" + items[2].text)
					})
				})
				//初始化数据
				getServer('app/member/addressList', "", function(res) {
					console.log(JSON.stringify(res))
					//				console.log(res.data.code)
					if(res.data != null){
						$('#address').val(res.data.address)
						$('#city').val(res.data.city)
						$('#phone').val(res.data.phone)
						$('#truename').val(res.data.truename)
					}
						
				});
				$('.addressSub').bind('tap', function() {
					if($('#city').val() == ""){
						mui.toast("请选择省市区")
						return
					}
					if($('#address').val() == ""){
						mui.toast("请输入详细地址")
						return
					}
					if($('#phone').val() == ""){
						mui.toast("请输入手机号")
						return
					}
					if(!isPoneAvailable($('#phone').val())){
						mui.toast("请正确输入手机号")
						return
					}
					if($('#truename').val() == ""){
						mui.toast("请输入收货人姓名")
						return
					}
					var subData = {
						address: $('#address').val(),
						city: $('#city').val(),
						phone: $('#phone').val(),
						truename: $('#truename').val()
					}
					console.log(JSON.stringify(subData))
					postServer('app/member/addAddress', $.param(subData), function(res) {
						console.log(JSON.stringify(res))
						mui.toast(res.message)
						if(parms.id == 1){
							plus.webview.getWebviewById('../product/product.html').evalJS("init()")
						}
						plus.webview.currentWebview().close()
					});
				})
			});
		</script>
	</body>

</html>